package cn.jyc.ssm03.ctrl;

import cn.jyc.ssm03.pojo.Bus_checks;
import cn.jyc.ssm03.pojo.Bus_rents;
import cn.jyc.ssm03.service.ChkService;
import cn.jyc.ssm03.service.RentsService;
import cn.jyc.ssm03.utils.IDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class RentsCtrl {

    @Autowired
    private RentsService rs;
    @Autowired
    private ChkService cs;

    @ResponseBody
    @RequestMapping("/getRentsID")
    public Map<String, String> getRID(String identity, String carnumber) {
        Map<String, String> res = new HashMap<>();
        res.put("identity", identity);
        res.put("carnumber", carnumber);
        res.put("rentid", IDUtil.getID("CZ"));
        res.put("opername", "admin");
        return res;
    }

    @ResponseBody
    @RequestMapping("addRent")
    public Map<String, String> addRent(Bus_rents br) {
        System.out.println(br);
        return rs.addRent(br);
    }

    @ResponseBody
    @RequestMapping("qryRents")
    public Map<String, Object> qryRents(@RequestParam(value = "page",defaultValue = "1") Integer p1,
                                        @RequestParam(value = "rows",defaultValue = "10") Integer p2,Bus_rents br){
        return rs.qryRents(p1, p2, br);
    }

    @ResponseBody
    @RequestMapping("addChk")
    public Map<String, String> addChk(Bus_checks bc) {
        return cs.addChk(bc);
    }

    @ResponseBody
    @RequestMapping("/getChkID")
    public String getChkID() {
        return IDUtil.getID("JC");
    }

    @ResponseBody
    @RequestMapping("qryChks")
    public Map<String, Object> qryChks(@RequestParam(value = "page",defaultValue = "1") Integer p1,
                                        @RequestParam(value = "rows",defaultValue = "10") Integer p2,Bus_checks br){
        return cs.qryChks(p1, p2, br);
    }
}
